<?php

namespace App\Http\Controllers\Pay\Order;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Http\Resources\Common\DataResource;
use App\Http\Resources\Common\DatasResource;
use App\Services\Pay\Order\TransferService;
use App\Services\Postman\ApiService as PostmanApiService;

class TransferController extends Controller
{

    /**
     * 导出数据
     */
    public function export(Request $request)
    {
        TransferService::create()->getList($request, true);
    }

    /**
     * 获取数据列表
     */
    public function getList(Request $request)
    {
        list ($collection, $total, $stats) = TransferService::make()->getList($request);

        return DatasResource::make($collection)->setPaginateTotal($total)->setAttribute('stats', $stats);
    }

    /**
     * 获取订单信息，并刷新订单状态
     */
    public function refresh(Request $request)
    {
        $data = $request->validate([
            'plat_code' => 'required|string|max:64',
            'plat_sn' => 'required|string|max:128',
        ]);

        $order = PostmanApiService::post(PostmanApiService::URI_ORDER_INFO, $data);

        return new DataResource($order);
    }
}
